<?php
namespace app\servergoods\model;

use \app\manage\model\BaseModel;
// 商品分类模型层
class Goods extends BaseModel
{
	protected $name = 'goods';
    protected $connection = 'db_config_goods';
    protected $dateFormat = 'Y-m-d H:i:s';
    protected $statusText = [-1=>'准备资料中', 0=>'待审核', 1=>'通过', 2=>'审核失败', 3=>'下架', 4=>'售空'];
    protected $append = [];   //根据id修改数量进行saveAll方法时，append数组要为空，不知道是个毛原因！

    /*一对一关联模型*/
    /*public function goodsCategory()
    {
        return $this->hasOne('GoodsCategory','id','cate_id')->field('id,name,status,cate_attrs');
    }*/

    public function setOrtherPriceAttr($value, $data)
    {
        return json_encode($data['orther_price']);
    }

    public function setOrtherInfoAttr($value, $data)
    {
        return json_encode($data['orther_info']);
    }

    public function setGoodsAttrsAttr($value, $data)
    {
        return json_encode($data['goods_attrs']);
    }

    public function setSearchFieldsAttr($value, $data)
    {
        return json_encode($data['search_fields']);
    }
   
    public function getOrtherPriceAttr($value,$data)
    {
        return json_decode($data['orther_price'], true);
    }

    public function getOrtherInfoAttr($value, $data)
    {
        return json_decode($data['orther_info'], true);
    }

    public function getGoodsAttrsAttr($value, $data)
    {
        return json_decode($data['goods_attrs'], true);
    }

    public function getSearchFieldsAttr($value, $data)
    {
        $res = json_decode($data['search_fields'], true);
        foreach ($res as $k => &$v) {
            $v = trim($v,",");
        }
        return $res;
    }

    public function getImgsUrlsAttr($value, $data)
    {
        return explode(",", $data['imgs_urls']);
    }

    public function getImgsIdsAttr($value, $data)
    {
        return explode(",", $data['imgs_ids']);
    }

    
}
